/**
* @File    :   wechat.go
* @Time    :   2022/05/07
* @Author  :   Mz100
* @Desc    :   微信配置，获取实例等处理
 */

package wechat

import (
	"github.com/silenceper/wechat/v2"
	"github.com/silenceper/wechat/v2/miniprogram"
	miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
	"xdingtec.cn/xdkaika/app"
)

type config struct {
	AppID     string
	AppSecret string
	MchID     string
	Key       string
	NotifyURL string
}

func GetConfig() (cfg *config) {
	cfg = &config{
		AppID:     app.CONFIG.Wechat.AppID,
		AppSecret: app.CONFIG.Wechat.AppSecret,
		MchID:     app.CONFIG.Wechat.MchID,
		Key:       app.CONFIG.Wechat.MchKey,
		NotifyURL: app.CONFIG.Wechat.NotifyURL,
	}
	return
}

/**
 *获取小程序示例
 */
func GetMiniProgram() *miniprogram.MiniProgram {
	wx := wechat.NewWechat()
	cache := app.REDIS
	config := GetConfig()
	cfg := &miniConfig.Config{
		AppID:     config.AppID,
		AppSecret: config.AppSecret,
		Cache:     cache,
	}
	return wx.GetMiniProgram(cfg)
}
